const fs = require("fs");
const path = require("path");
import { getCurrentTime, isDevelopment } from "./index";

/**
 * 日志函数
 * @param content 日志内容
 */
export function logger(content) {
  if (isDevelopment()) {
    console.log(content);
  } else {
    try {
      const logFilePath = path.join(__dirname, "app.log");
      const logMessage = `${getCurrentTime()}:::${JSON.stringify(content)}\n`;
      fs.appendFile(logFilePath, logMessage, (err) => {
        if (err) {
          console.error("Failed to write log to file:", err);
        }
      });
    } catch (error) {
      console.error("An error occurred while writing log:", error);
    }
  }
}
